#!/usr/bin/env python
# -*- coding:utf-8 -*-
import json

from flask import jsonify, request
from flask_restful import Resource, reqparse

from service.pptChatDocumentService import PptChatDocumentService
from service.pptChatService import PptChatService
from utils import commons


class PptChatOtherResource(Resource):
    @classmethod
    def chat_ppt_framework_basic(cls):
        content = request.get_data()
        kwargs = json.loads(content)
        kwargs = commons.put_remove_none(**kwargs)

        res = PptChatService.chat_ppt_framework(**kwargs)
        return res

    @classmethod
    def get_chat_history(cls):
        parser = reqparse.RequestParser()
        parser.add_argument('ppt_id', location='args', required=False, help='ppt_id参数类型不正确或缺失')

        kwargs = parser.parse_args()
        kwargs = commons.put_remove_none(**kwargs)

        res = PptChatService.get_formatted_chat_history(**kwargs)
        return jsonify(code=res['code'], message=res['message'], data=res['data'])

    @classmethod
    def chat_ppt_framework_with_document(cls):
        # content = request.get_data()
        # kwargs = json.loads(content)
        # kwargs = commons.put_remove_none(**kwargs)

        parser = reqparse.RequestParser()
        parser.add_argument('ppt_id', location='form', required=True, help='ppt_id参数类型不正确或缺失')
        parser.add_argument('content', location='form', required=True, help='content参数类型不正确或缺失')

        kwargs = parser.parse_args()
        kwargs = commons.put_remove_none(**kwargs)

        file = request.files.get('file')
        kwargs['file'] = file

        res = PptChatDocumentService.chat_ppt_framework_with_document(**kwargs)
        return res


